package top.zlhy7.service;

import com.github.lianjiatech.retrofit.spring.boot.annotation.Intercept;
import com.github.lianjiatech.retrofit.spring.boot.annotation.RetrofitClient;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.Path;
import top.zlhy7.interceptor.TimeStampInterceptor;
import top.zlhy7.vo.HelloVo;

import java.util.List;
import java.util.Map;

/**
 * @author 任勇
 * @date 2021/12/22 14:53
 * @description
 * 参考文档 https://mp.weixin.qq.com/s?__biz=MzU4MDUyMDQyNQ==&mid=2247501886&idx=2&sn=07be335f37c3936356c4b5f136f33017&scene=126&sessionid=1640135040#rd
 */
@RetrofitClient(baseUrl = "${test.baseUrl}")
@Intercept(handler = TimeStampInterceptor.class, include = {"/test/**"}, exclude = "/api/test/savePerson")
public interface HttpApi {
    @GET("/test/list")
    List<HelloVo> list();
    @GET("/test/{id}")
    HelloVo findById(@Path("id") Integer id);
    @POST("/test")
    Void save(@Body HelloVo helloVo);
    @PUT("/test")
    Void update(@Body HelloVo helloVo);
    @DELETE("/test/{id}")
    Void delete(@Path("id") Integer id);

    /**
     * 表单提交
     * @param param
     * @return
     */
    @FormUrlEncoded
    @POST("/test/formSubmit")
    Void formSubmit(@FieldMap Map<String, Object> param);
    /**
     * 单文件上传.todo 这个没成功正在尝试
     * @param file
     * @return
     */
    @POST("/test/upload")
    @Multipart
    Void upload(@Part MultipartBody.Part file);

    /**
     * 下载
     */
    @GET("/test/download")
    Response<ResponseBody> download();
}
